package com.wanggsx.library.util;

import android.app.Activity;
import android.graphics.Color;

import com.githang.statusbar.StatusBarCompat;
import com.wanggsx.library.util.fun.navigationbar.NavigationBarUtil;

public class UtilsStatusBarNavigationBar {

    /**
     * 利用反射获取状态栏高度
     * @return
     */
    public static int getStatusBarHeight(Activity activity) {
        int result = 0;
        //获取状态栏高度的资源id
        int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = activity.getResources().getDimensionPixelSize(resourceId);
        }
        UtilsLog.d("statusbar height : " + result + " dp : " + UtilsSize.px2dp(60));
        return result;
    }

    /** 如果手机有底部虚拟导航栏需要调整view的高度 */
    public static void translateNavigationBar(Activity activity) {
        if (NavigationBarUtil.hasNavigationBar(activity)) {
            NavigationBarUtil.initActivity(activity.findViewById(android.R.id.content));
        }
    }

    /** 设置白色透明状态栏 */
    public static void setWhiteTextTransparentStatusBar(Activity context) {
        StatusBarCompat.setTranslucent(context.getWindow(), true);
        StatusBarCompat.setLightStatusBar(context.getWindow(), false);
    }

    /** 设置黑色透明状态栏 */
    public static void setBlackTexttTransparentStatusBar(Activity context) {
        StatusBarCompat.setTranslucent(context.getWindow(), true);
        StatusBarCompat.setLightStatusBar(context.getWindow(), true);
    }

    /** 设置指定文字颜色不透明状态栏 */
    public static void setTextColorNotTransparentStatusBar(Activity context,String colorName) {
        StatusBarCompat.setStatusBarColor(context,Color.parseColor(colorName));
    }

//    public static void setStatusBarBackground(Activity activity, Drawable bgdrawable, String colorName, boolean isPaddingTop){
//        //设置 paddingTop
//        ViewGroup rootView = (ViewGroup) activity.getWindow().getDecorView().findViewById(android.R.id.content);
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            if (isPaddingTop) {
//                int paddingTop = UtilsStatusBarNavigationBar.getStatusBarHeight(activity);
//                rootView.setPadding(0, paddingTop, 0, 0);
//            }
//            //5.0 以上直接设置状态栏颜色
//            if (bgdrawable!=null){
//                activity.getWindow().setStatusBarColor(Color.parseColor("#00000000"));
//                //activity.getWindow().setBackgroundDrawable(bgdrawable);
//            }else{
//                StatusBarCompat.setStatusBarColor(activity,Color.parseColor(colorName));
//            }
//        } else {
//            //根布局添加占位状态栏
//            //5.0以下不支持占位view
//            boolean isNew = true;
//            ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
//            View statusBarView = decorView.findViewWithTag("100010");
//            if (statusBarView==null){
//                isNew = false;
//                if (bgdrawable!=null){
//                    statusBarView = new View(activity);
//                    statusBarView.setTag("100010");
//                    statusBarView.setBackgroundColor(Color.parseColor("#00000000"));
//                    statusBarView.setBackground(bgdrawable);
//                    int paddingTop = 0;
//                    if (isPaddingTop) {
//                        paddingTop = UtilsStatusBarNavigationBar.getStatusBarHeight(activity);
//                    }
//                    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, paddingTop);
//                    decorView.addView(statusBarView, lp);
//                }else{
//                    StatusBarCompat.setStatusBarColor(activity,Color.parseColor(colorName));
//                }
//            }else{
//                if (bgdrawable!=null){
//                    statusBarView.setBackgroundColor(Color.parseColor("#00000000"));
//                    statusBarView.setBackground(bgdrawable);
//                    int paddingTop = 0;
//                    if (isPaddingTop) {
//                        paddingTop = UtilsStatusBarNavigationBar.getStatusBarHeight(activity);
//                    }
//                    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
//                            paddingTop);
//                    decorView.addView(statusBarView, lp);
//                }else{
//                    decorView.removeView(statusBarView);
//                    StatusBarCompat.setStatusBarColor(activity,Color.parseColor(colorName));
//                }
//            }
//        }
//    }

}
